﻿  $.includeFile(['/Scripts/Pager/pagination.css']);
  var CSP_Pager = function () {
      this.CallBack = undefined;
      this.PagerClientId = "";  //控件Id
      this.BtnOKClientId = "";  //确定跳转控件Id
      this.Txt_ItemCountId = ""; /*总数量*/
      this.Txt_Items_Per_PageId = ""; /*每页显示的列表数*/
      this.Txt_Num_Display_EntriesId = ""; /*分页链接显示数*/
      this.Txt_Num_Edge_EntriesId = ""; /*起始与结束点的数目*/
      this.Txt_Prev_TextId = ""; /*“上一页”标签：*/
      this.Txt_Next_TextId = ""; /*“下一页”标签：*/
      this.Txt_CurrentIndexId = ""; /*当前页*/
      this.Txt_LengthId = "";
      this.Page_InfoId = "";  /*显示的总数目*/
      this.IsAutoPostBack = false; /*是否为自动回发*/

      this.IsFirstLoad = true; /*防止二次加载 indexChange*/
      this.Options = {
          callback: this.CallBack, /*索引改变时触发的回调函数(注意:如果用户控件AutoPostBack=true,客户端指定的回调函数将失效)*/
          items_per_page: 5,      /*每页显示的列表数*/
          num_display_entries: 10, /*分页链接显示数*/
          num_edge_entries: 2,     /*起始与结束点的数目*/
          prev_text: "上一页",    /*“上一页”标签：*/
          next_text: "下一页",    /*“下一页”标签：*/
          current_page: 0,          /*当前选中页*/
          length: 100,         /*当前总页数*/
          itemcount: 0        /*总数量*/
      };
      this.Init = function () {
          var that = this;

          that.BeforeInit();
          //总数目
          //var length = 100;
          // 重新创建分页参数
          //$("#"+that.PagerClientId+"_Pagination").pagination(that.Options.itemcount, that.Options);
          that.Refresh();
          $("#" + that.BtnOKClientId).click(function () {
              return that.IndexChangeSubmit();
          });
      }; /*初始化前先加载html信息*/
      this.BeforeInit = function () {
          var that = this;

          that.Options.itemcount = $("#" + that.Txt_ItemCountId).val(); /*总数量*/
          that.Options.items_per_page = parseInt($("#" + that.Txt_Items_Per_PageId).val()); /*每页显示的列表数*/
          that.Options.num_display_entries = parseInt($("#" + that.Txt_Num_Display_EntriesId).val()); /*分页链接显示数*/
          that.Options.num_edge_entries = parseInt($("#" + that.Txt_Num_Edge_EntriesId).val()); /*起始与结束点的数目*/
          that.Options.prev_text = $("#" + that.Txt_Prev_TextId).val(); /*“上一页”标签：*/
          that.Options.next_text = $("#" + that.Txt_Next_TextId).val(); /*“下一页”标签：*/
          that.Options.current_page = parseInt($("#" + that.Txt_CurrentIndexId).val()) - 1; /*当前页*/
          that.Options.length = parseInt($("#" + that.Txt_LengthId).val());
          that.Options.callback = that.CallBack; //补充
          /*避免重引入HTML*/
          var htmlspecialchars = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" }
          $.each(htmlspecialchars, function (k, v) {
              that.Options.prev_text = that.Options.prev_text.replace(k, v);
              that.Options.next_text = that.Options.next_text.replace(k, v);
          });
      };
      this.Refresh = function ()/*刷新*/
      {
          var that = this;
          //alert(that.Options.length);
          //总数目
          $("#" + that.Page_InfoId).html("共" + (that.Options.itemcount) + "条/" + that.Options.length + "页");
          // 重新创建分页参数
          $("#" + that.PagerClientId + "_Pagination").pagination(that.Options.itemcount, that.Options);

          $("#" + that.Txt_Items_Per_PageId).val(that.Options.items_per_page); /*每页显示的列表数*/
          $("#" + that.Txt_Num_Display_EntriesId).val(that.Options.num_display_entries); /*分页链接显示数*/
          $("#" + that.Txt_Num_Edge_EntriesId).val(that.Options.num_edge_entries); /*起始与结束点的数目*/
          $("#" + that.Txt_Prev_TextId).val(that.Options.prev_text); /*“上一页”标签：*/
          $("#" + that.Txt_Next_TextId).val(that.Options.next_text); /*“下一页”标签：*/
          $("#" + that.Txt_CurrentIndexId).val(that.Options.current_page + 1); /*当前页*/
          $("#" + that.Txt_LengthId).val(that.Options.length); /*当前页*/
          $("#" + that.Txt_ItemCountId).val(that.Options.itemcount); /*总数量*/
      };
      this.IndexChange = function (page_index, jq) {
          var that = this;
          if (that.IsFirstLoad) {
              that.IsFirstLoad = false;
              return;
          }

          $("#" + that.Txt_CurrentIndexId).val(page_index + 1); /*当前页*/
          $("#" + that.BtnOKClientId).click();



      };
      this.IndexChangeSubmit = function () {
          var that = this;
          //如果回发服务器
          if (that.IsAutoPostBack) {
              return true;
          } else {
              that.Refresh();
              return false;
          }

      };

  };